home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 114 / macaddict114.cdr / Software / Utilities / macam.0.8.4.dmg / macam sources / app_specific / MyMovieDocument.m < prev    next >
Encoding:
Text File  |  2002-11-12  |  2.4 KB  |  77 lines

  1. #import "MyMovieDocument.h"
  2. #import "MyMovieWindowController.h"
  3. #import "MyNSMovieExtensions.h"
  4.  
  5. @implementation MyMovieDocument
  6.  
  7. - (id) init {
  8.     if (!initWillLoadFile) {    //We should make a standard movie
  9.         MyMovieRecorder* recorder=[[MyMovieRecorder alloc] initWithSize:NSMakeSize(640,480)
  10.                                                             compression:@"JPEG"
  11.                                                                 quality:0.8f
  12.                                                                    path:NULL];
  13.         NSString* tempMoviePath;
  14.  
  15. /*
  16.  int i;
  17.         NSArray *paths=[[NSBundle mainBundle] pathsForResourcesOfType:@"jpg" inDirectory:nil];
  18.         for (i=0;i<[paths count];i++) {
  19.             NSImage* img=[[[NSImage alloc] initWithContentsOfFile:[paths objectAtIndex:i]] autorelease];
  20.             NSBitmapImageRep* ir=[[img representations] objectAtIndex:0];
  21.             [recorder addFrame:ir at:((float)i)/10.0f];
  22.         }
  23.  */
  24.         [recorder finishRecordingAt:10.0f];
  25.         tempMoviePath=[recorder moviePath];
  26.         [recorder keepMovieFile];
  27.         self=[super init];
  28.         if (self) [self readFromFile:tempMoviePath ofType:@"QuickTime Movie"];
  29.     } else {
  30.         self=[super init];
  31.     }
  32.     return self;
  33. }
  34.  
  35. - (id)initWithContentsOfFile:(NSString *)fileName ofType:(NSString *)docType {
  36.     initWillLoadFile=YES;
  37.     self=[super initWithContentsOfFile:fileName ofType:docType];
  38.     return self;
  39. }
  40.  
  41.  
  42. - (void)makeWindowControllers {
  43.     MyMovieWindowController* controller=[[[MyMovieWindowController alloc] init] autorelease];
  44.     [self addWindowController:controller];
  45. }
  46.  
  47. - (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)docType {
  48.     if (![docType isEqualToString:@"QuickTime Movie"]) {
  49.         NSLog(@"unknown movie type %@",docType);
  50.         return NO;
  51.     }
  52.     if (movie) [movie release];
  53.     movie=NULL;
  54.     movie=[[NSMovie alloc] initWithURL:[NSURL fileURLWithPath:fileName] byReference:NO];
  55.     if (!movie) return NO;
  56.     return YES;
  57. }
  58.  
  59. - (BOOL)writeToFile:(NSString *)fileName ofType:(NSString *)type {
  60.     NSData* data=[NSMutableData dataWithLength:10];
  61.     if (![type isEqualToString:@"QuickTime Movie"]) return NO;
  62.     [data writeToFile:fileName atomically:YES];
  63.     return [movie writeToFile:fileName];
  64. }
  65.  
  66. - (void) close {
  67.     [super close];
  68.     [movie release];
  69.     movie=NULL;
  70. }
  71.  
  72. - (NSMovie*) innerMovie {
  73.     return movie;
  74. }
  75.  
  76. @end
  77.